const CDBSave = require('./dbsave')

class Print_info extends CDBSave.CDBSave{
    constructor(){
        super();
    }

    filePath(){
        return 'Print_Info_changda.json'
    }

    load(data){
        if(!data)return

        this.notices = data;
    }

    save(){
        return this.notices;
    }

    Add_PrintTask(message,Info){
        let id = this.notices.length + 1;
        Info.id = id;
        let New_Message = Object.assign(message,Info);
        let Add_PrintTask = new Task_PrintChild(New_Message);
        this.notices.push(Add_PrintTask);
    }

    GetPrintTask(){
        return this.notices;
    }


    // 接手任务
    Get_PrintTask(id,number,Select_number){
        for(let i=0;i<this.notices.length;i++){
            if(this.notices[i].id == id && this.notices[i].number == number){
                this.notices[i].select_paoshou = Select_number;
                break; 
            }
        }
    }

    //完成打印任务
    Finish_Task(id,number){
        console.log(id,number)
        for(let i=0; i<this.notices.length; i++){
            if(this.notices[i].id == id && this.notices[i].number == number){
                this.notices[i].whether_finished = 1;
                break;
            }
        }
    }
}

class Task_PrintChild{
    constructor(message){
        this.load(message)
    }

    load(data){
        this.id = data.id;
        this.name = data.name;
        this.number = data.number;
        this.telephone_number = data.telephone_number;
        this.give_Address = data.address;
        this.get_Address = data.Address_Print;
        this.Notes = data.Notes;
        this.money = data.money;
        this.select_paoshou = "";
        this.whether_finished = 0;
    }


    save(){
        return{
            id:this.id,
            name:this.name,
            number:this.number,
            telephone_number:this.telephone_number,
            give_Address:this.give_Address,
            get_Address:this.get_Address,
            Notes:this.Notes,
            money:this.money,
            select_paoshou:this.select_paoshou,
            whether_finished:this.whether_finished
        }
    }
}



module.exports = {Print_info,Task_PrintChild}